// components/home/index.js
const app = getApp();
let that;
Component({
  options: {
    addGlobalClass: true
  },

  /**
   * 组件的属性列表
   */
  properties: {
  },

  /**
   * 组件的初始数据
   */
  data: {
    pageCur: '',
    mainActiveIndex: 0,
    activeId: null,
    contentHeight: 0 ,// 动态计算的高度
    items: [
      { text: '抖店运营0到1课程' },
      { text: '视频号小店开通及运营' },
      { text: '手机剪映短视频剪辑' }
    ],
     // 右侧内容数据（二维数组结构）
     contentList: [
      [ // 分类1对应内容
        {
          avator: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E8%A7%86%E9%A2%91%E5%8F%B7%E8%AF%BE%E7%A8%8B/%E6%8A%96%E5%BA%97%E8%AF%BE%E7%A8%8B/%E6%8A%96%E5%BA%97%E5%B0%81%E9%9D%A2%E5%9B%BE.jpg",
          videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E8%A7%86%E9%A2%91%E5%8F%B7%E8%AF%BE%E7%A8%8B/%E6%8A%96%E5%BA%97%E8%AF%BE%E7%A8%8B/%E6%8A%96%E5%BA%97%E7%AC%AC%E4%B8%80%E8%8A%82%E8%AF%BE.mp4",
          id: 1,
          recommend_id: 1,
          subtitle: "بىرىنجى سائەتلىك دەرسلىكى",
          title: "دوۋدىيەن دەرسلىكى ",
          price:"0.00",
          originalPrice:"88.00"
        },
        {
          avator: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E8%A7%86%E9%A2%91%E5%8F%B7%E8%AF%BE%E7%A8%8B/%E6%8A%96%E5%BA%97%E8%AF%BE%E7%A8%8B/%E6%8A%96%E5%BA%97%E5%B0%81%E9%9D%A2%E5%9B%BE.jpg",
          videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E8%A7%86%E9%A2%91%E5%8F%B7%E8%AF%BE%E7%A8%8B/%E6%8A%96%E5%BA%97%E8%AF%BE%E7%A8%8B/%E6%8A%96%E5%BA%97%E7%AC%AC%E4%BA%8C%E8%8A%82%E8%AF%BE.mp4",
          id: 2,
          recommend_id: 2,
          subtitle: "ئىككىنجى سائەتلىك دەرسلىكى",
          title: "دوۋدىيەن دەرسلىكى ",
          price:"0.00",
          originalPrice:"99.00"
        },
      ],
      [ // 分类2对应内容
        {
          avator: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E8%A7%86%E9%A2%91%E5%8F%B7%E8%AF%BE%E7%A8%8B/%E8%A7%86%E9%A2%91%E5%8F%B7%E5%B0%81%E9%9D%A2%E5%9B%BE.jpg",
          videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E8%A7%86%E9%A2%91%E5%8F%B7%E8%AF%BE%E7%A8%8B/%E8%A7%86%E9%A2%91%E5%8F%B7%E7%AC%AC%E4%BA%8C%E8%8A%82%E8%AF%BE%E4%B8%8A.mp4",
          id: 1,
          recommend_id: 1,
          subtitle: "بىرىنجى سائەتلىك دەرسلىكى",
          title: "شىپىنخاۋ دەرسلىكى ",
          price:"0.00",
          originalPrice:"88.00"
        },
        {
          avator: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E8%A7%86%E9%A2%91%E5%8F%B7%E8%AF%BE%E7%A8%8B/%E8%A7%86%E9%A2%91%E5%8F%B7%E5%B0%81%E9%9D%A2%E5%9B%BE.jpg",
          videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E8%A7%86%E9%A2%91%E5%8F%B7%E8%AF%BE%E7%A8%8B/%E8%A7%86%E9%A2%91%E5%8F%B7%E7%AC%AC%E4%BA%8C%E8%8A%82%E8%AF%BE%E4%B8%8B.mp4",
          id: 2,
          recommend_id: 2,
          subtitle: "شىپىنخاۋ سائەتلىك دەرسلىكى",
          title: "شىپىنخاۋ دەرسلىكى ",
          price:"0.00",
          originalPrice:"99.00"
        },
      ],
      [ // 分类4对应内容
        {
          avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
          videoUrl: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE%E7%A8%8B%E7%AC%AC%E4%B8%80%E8%AF%BE.mp4 ",
          id: 1,
          recommend_id: 1,
          subtitle: "بىرىنجى سائەتلىك دەرسلىكى",
          title: "جىيەنيىڭ دەرسلىكى ",
          price:"0.00",
          originalPrice:"88.00"
        },
        {
          avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
          videoUrl: "https://qiniu.camino.top/%E5%89%AA%E6%98%A0%E7%AC%AC%E4%BA%8C%E8%AF%BE.mp4",
          id: 2,
          recommend_id: 2,
          subtitle: "ئىككىنجى سائەتلىك دەرسلىكى",
          title: "جىيەنيىڭ دەرسلىكى ",
          price:"0.00",
          originalPrice:"99.00"
        },
        {
          avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
          videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E5%89%AA%E6%98%A0%E8%AF%BE%E7%A8%8B%E7%AC%AC%E4%B8%89%E8%AF%BE.mp4",
          id: 3,
          recommend_id: 3,
          subtitle: "ئۈچىنجى سائەتلىك دەرسلىكى",
          title: "جىيەنيىڭ دەرسلىكى ",
          price:"0.00",
          originalPrice:"121.00"
        },
        {
          avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
          videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E5%89%AA%E6%98%A0%E7%AC%AC%E5%9B%9B%E8%AF%BE.mp4",
          id: 4,
          recommend_id: 4,
          subtitle: "تۆتىنجى سائەتلىك دەرسلىكى",
          title: "جىيەنيىڭ دەرسلىكى ",
          price:"0.00",
          originalPrice:"55.00"
        },
         {
          avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
          videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E5%89%AA%E6%98%A0%E7%AC%AC%E4%BA%94%E8%AF%BE.mp4",
          id: 5,
          recommend_id: 5,
          subtitle: "بەشىنجى سائەتلىك دەرسلىكى",
          title: "جىيەنيىڭ دەرسلىكى ",
          price:"0.00",
          originalPrice:"121.00"
        },
        {
          avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
          videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E5%89%AA%E6%98%A0%E7%AC%AC%E5%85%AD%E8%AF%BE.mp4",
          id: 6,
          recommend_id: 6,
          subtitle: "ئالتىنجى سائەتلىك دەرسلىكى",
          title: "جىيەنيىڭ دەرسلىكى ",
          price:"0.00",
          originalPrice:"121.00"
        },
        {
          avator: "https://qiniu.camino.top/%E6%89%8B%E6%9C%BA%E7%89%88%E5%89%AA%E6%98%A0%E8%AF%BE.jpg",
          videoUrl: "https://qiniu.camino.top/%E6%8E%A8%E8%8D%90/%E5%89%AA%E6%98%A0%E7%AC%AC%E4%B8%83%E8%AF%BE.mp4",
          id: 7,
          recommend_id: 7,
          subtitle: "يەتتىنجى سائەتلىك دەرسلىكى",
          title: "جىيەنيىڭ دەرسلىكى ",
          price:"0.00",
          originalPrice:"78.00"
        },
      ]
    ],
    
  },

  /**
   * 组件的方法列表
   */
  attached() {
    that = this;
  },

  methods: {
    componentInnerFunction(e) {
    
      console.log(e)
      that.setData({
        pageCur: e,
      })
    },
      // actions
  onClickNav({ detail = {} }) {
    console.log("2222==",detail)
    const index = detail.index
    console.log('切换到分类:', index )
    this.setData({
      mainActiveIndex: index,
      activeId: null // 切换分类时重置右侧选择
    });
        // 这里可以加载对应分类的数据
        this.loadContentData(index)
  },
    // 模拟加载分类数据
    loadContentData(index) {
      // 实际项目中这里应该是网络请求
      console.log('加载分类' + index  + '的数据')
    },

  onClickItem(event) {
    // 从 event.currentTarget.dataset 获取 data-id 和 data-item
    const { id, item } = event.currentTarget.dataset;
    console.log('点击的ID:', id);      // 输出 data-id 的值
    console.log('点击的Item:', item);  // 输出 data-item 的值
    
    // 示例：设置 activeId 为点击的 id
    this.setData({
      activeId: id
    });

    wx.navigateTo({
      url: '/pages/courseDetail/courseDetail?item=' + encodeURIComponent(JSON.stringify(item)), // 假设路径为 /pages/student/studentDetail/
      fail(err) {
        console.error('跳转失败:', err);
      }
    });


  }

  },

})